package com.cecsmsserve.utils;

import lombok.Data;

@Data
public class CommonResult<T> {
    private Integer code;
    private String message;
    private T result;

    public CommonResult() {
    }

    public CommonResult(Integer code, String message, T result) {
        this.code = code;
        this.message = message;
        this.result = result;
    }

    /**
     * 成功返回结果
     */
    public static <T> CommonResult<T> success(T data) {
        return new CommonResult<>(200, "操作成功", data);
    }

    /**
     * 成功返回结果
     */
    public static <T> CommonResult<T> success(String message, T data) {
        return new CommonResult<>(200, message, data);
    }

    /**
     * 失败返回结果
     */
    public static <T> CommonResult<T> failed(String message) {
        return new CommonResult<>(500, message, null);
    }

    /**
     * 失败返回结果
     */
    public static <T> CommonResult<T> failed(Integer code, String message) {
        return new CommonResult<>(code, message, null);
    }

    /**
     * 参数验证失败返回结果
     */
    public static <T> CommonResult<T> validateFailed(String message) {
        return new CommonResult<>(400, message, null);
    }

    /**
     * 未登录返回结果
     */
    public static <T> CommonResult<T> unauthorized(String message) {
        return new CommonResult<>(401, message, null);
    }

    /**
     * 未授权返回结果
     */
    public static <T> CommonResult<T> forbidden(String message) {
        return new CommonResult<>(403, message, null);
    }

    /**
     * 资源未找到返回结果
     */
    public static <T> CommonResult<T> notFound(String message) {
        return new CommonResult<>(404, message, null);
    }

    /**
     * 设置为未找到状态
     */
    public void setNotFound() {
        this.code = 404;
        this.message = "未找到相关资源";
    }

    /**
     * 失败返回结果
     */
    public static <T> CommonResult<T> failure(String message) {
        return new CommonResult<>(500, message, null);
    }
} 